//
//  MVPlayViewController.m
//  LastTemp
//
//  Created by dllo on 15/4/22.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "MVPlayViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface MVPlayViewController ()

@end

@implementation MVPlayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    MPMoviePlayerController *mvMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:self.mvPassURL]];
    [mvMoviePlayer.view setFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:mvMoviePlayer.view];
    [mvMoviePlayer setFullscreen:YES animated:YES]; // 切换全屏模式
    [mvMoviePlayer play];
    
    // 使用NSNotificationCenter类注册一个观察者, 该观察者将监视来自对象mvMoviePlayer的特定通知, 并在收到这种特定通知的时候调用指定的方法
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:mvMoviePlayer];
}
- (void)playMovieFinished:(NSNotification *)theNotification{
    MPMoviePlayerController *mvMoviePlayer = [theNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:mvMoviePlayer];
    [mvMoviePlayer.view removeFromSuperview];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
